package com.hbnu.service;

import com.hbnu.dao.WordDAO;
import com.hbnu.entity.Word;
import java.util.List;

public class WordService {
    private WordDAO wordDAO = new WordDAO();

    // 按字母查询单词
    public List<Word> searchWord(String letter) {
        if (letter == null || letter.trim().isEmpty()) {
            throw new IllegalArgumentException("请输入单词字母");
        }

        List<Word> words = wordDAO.searchWordByLetter(letter);
        if (words.isEmpty()) {
            throw new RuntimeException("未找到包含 [" + letter + "] 的单词");
        }
        return words;
    }

    // 根据ID查询单词
    public Word getWordById(int wordId) {
        if (wordId <= 0) {
            throw new IllegalArgumentException("单词ID必须为正数");
        }

        Word word = wordDAO.getWordById(wordId);
        if (word == null) {
            throw new RuntimeException("未找到ID为" + wordId + "的单词");
        }
        return word;
    }
}
